clear all

********************************************************************************
********************************************************************************
**** When Can We Trust Regression Discontinuity Design Estimates from Close ****
*************** Elections? Evidence from Experimental Benchmarks ***************
********************************************************************************
********************************************************************************

* This file produces Figure OA4 in Online Appendix C of De Magalhaes et al. 
* (Political Analysis).

cd "$dir"
use "$dir/data/personal_incumbency_advantage.dta", clear

********************************************************************************

est clear

eststo: rdrobust electednextelection rv if rv!=0 & rv!=. & country=="Brazil", c(0) p(1) all vce(cluster constituency) bwselect(mserd) kernel(triangular) rho(0.85)
eststo: rdrobust electednextelection rv if rv!=0 & rv!=. & country=="Brazil", c(0) p(1) all vce(cluster constituency) bwselect(mserd) kernel(uniform) rho(1)
eststo: rdrobust electednextelection rv if rv!=0 & rv!=. & country=="Brazil", c(0) p(1) all vce(cluster constituency) bwselect(mserd) kernel(epanechnikov) rho(0.898) 
eststo: rdrobust electednextelection rv if rv!=0 & rv!=. & country=="Brazil", c(0) p(1) all vce(cluster constituency) bwselect(cerrd) kernel(triangular) rho(0.85)
eststo: rdrobust electednextelection rv if rv!=0 & rv!=. & country=="Brazil", c(0) p(1) all vce(cluster constituency) bwselect(cerrd) kernel(uniform) rho(1)
eststo: rdrobust electednextelection rv if rv!=0 & rv!=. & country=="Brazil", c(0) p(1) all vce(cluster constituency) bwselect(cerrd) kernel(epanechnikov) rho(0.898)
eststo: rdrobust electednextelection rv if rv!=0 & rv!=. & country=="Brazil", c(0) p(2) all vce(cluster constituency) bwselect(mserd) kernel(triangular) rho(0.887)
eststo: rdrobust electednextelection rv if rv!=0 & rv!=. & country=="Brazil", c(0) p(2) all vce(cluster constituency) bwselect(mserd) kernel(uniform) rho(1)
eststo: rdrobust electednextelection rv if rv!=0 & rv!=. & country=="Brazil", c(0) p(2) all vce(cluster constituency) bwselect(mserd) kernel(epanechnikov) rho(0.924) 
eststo: rdrobust electednextelection rv if rv!=0 & rv!=. & country=="Brazil", c(0) p(2) all vce(cluster constituency) kernel(triangular) bwselect(cerrd) rho(0.887)
eststo: rdrobust electednextelection rv if rv!=0 & rv!=. & country=="Brazil", c(0) p(2) all vce(cluster constituency) bwselect(cerrd) kernel(uniform) rho(1)
eststo: rdrobust electednextelection rv if rv!=0 & rv!=. & country=="Brazil", c(0) p(2) all vce(cluster constituency) bwselect(cerrd) kernel(epanechnikov) rho(0.924)

coefplot (est1, msymbol(triangle) mcolor(black) keep(Conventional Robust)) ///
	(est2, msymbol(square) mcolor(black) keep(Conventional Robust)) ///
	(est3, msymbol(circle) mcolor(black) keep(Conventional Robust)) ///
	(est4, msymbol(triangle) mlcolor(black) mfcolor(white) keep(Conventional Robust)) ///
	(est5, msymbol(square) mlcolor(black) mfcolor(white) keep(Conventional Robust)) ///
	(est6, msymbol(circle) mlcolor(black) mfcolor(white) keep(Conventional Robust)) ///
	(est7, msymbol(triangle) mcolor(gs12) keep(Conventional Robust)) ///
	(est8, msymbol(square) mcolor(gs12) keep(Conventional Robust)) ///
	(est9, msymbol(circle) mcolor(gs12) keep(Conventional Robust)) ///
	(est10, msymbol(triangle) mlcolor(gs12) mfcolor(white) keep(Conventional Robust)) ///
	(est11, msymbol(square) mlcolor(gs12) mfcolor(white) keep(Conventional Robust)) ///
	(est12, msymbol(circle) mlcolor(gs12) mfcolor(white) keep(Conventional Robust)), ///
	vertical scheme(sj) graphregion(color(white)) plotregion(lcolor(black)) ylabel(,format(%9.2f) angle(0)) ytitle("Point estimate") ///
	yline(0) xsize(16) ysize(9) ciopts(recast(rcap) color(black)) legend(label(2 "p = 1, MSE, triangular") label(4 "p = 1, MSE, uniform") ///
	label(6 "p = 1, MSE, epanechnikov") label(8 "p = 1, CER, triangular") ///
	label(10 "p = 1, CER, uniform") label(12 "p = 1, CER, epanechnikov") ///
	label(14 "p = 2, MSE, triangular") label(16 "p = 2, MSE, uniform") ///
	label(18 "p = 2, MSE, epanechnikov") label(20 "p = 2, CER, triangular") ///
	label(22 "p = 2, CER, uniform") label(24 "p = 2, CER, epanechnikov") cols(4)) ///
	subtitle("Panel A: Brazil", position(11))

graph save "$dir/temp/brazil_figureA3.gph", replace

est clear

eststo: rdrobust electednextelection rv if rv!=0 & rv!=. & country=="Colombia", c(0) p(1) all vce(cluster constituency) bwselect(mserd) kernel(triangular) rho(0.85)
eststo: rdrobust electednextelection rv if rv!=0 & rv!=. & country=="Colombia", c(0) p(1) all vce(cluster constituency) bwselect(mserd) kernel(uniform) rho(1)
eststo: rdrobust electednextelection rv if rv!=0 & rv!=. & country=="Colombia", c(0) p(1) all vce(cluster constituency) bwselect(mserd) kernel(epanechnikov) rho(0.898)
eststo: rdrobust electednextelection rv if rv!=0 & rv!=. & country=="Colombia", c(0) p(1) all vce(cluster constituency) bwselect(cerrd) kernel(triangular) rho(0.850)
eststo: rdrobust electednextelection rv if rv!=0 & rv!=. & country=="Colombia", c(0) p(1) all vce(cluster constituency) bwselect(cerrd) kernel(uniform) rho(1)
eststo: rdrobust electednextelection rv if rv!=0 & rv!=. & country=="Colombia", c(0) p(1) all vce(cluster constituency) bwselect(cerrd) kernel(epanechnikov) rho(0.898)
eststo: rdrobust electednextelection rv if rv!=0 & rv!=. & country=="Colombia", c(0) p(2) all vce(cluster constituency) bwselect(mserd) kernel(triangular) rho(0.887)
eststo: rdrobust electednextelection rv if rv!=0 & rv!=. & country=="Colombia", c(0) p(2) all vce(cluster constituency) bwselect(mserd) kernel(uniform) rho(1)
eststo: rdrobust electednextelection rv if rv!=0 & rv!=. & country=="Colombia", c(0) p(2) all vce(cluster constituency) bwselect(mserd) kernel(epanechnikov) rho(0.924)
eststo: rdrobust electednextelection rv if rv!=0 & rv!=. & country=="Colombia", c(0) p(2) all vce(cluster constituency) bwselect(cerrd) kernel(triangular) rho(0.887)
eststo: rdrobust electednextelection rv if rv!=0 & rv!=. & country=="Colombia", c(0) p(2) all vce(cluster constituency) bwselect(cerrd) kernel(uniform) rho(1)
eststo: rdrobust electednextelection rv if rv!=0 & rv!=. & country=="Colombia", c(0) p(2) all vce(cluster constituency) bwselect(cerrd) kernel(epanechnikov) rho(0.924)

coefplot (est1, msymbol(triangle) mcolor(black) keep(Conventional Robust)) ///
	(est2, msymbol(square) mcolor(black) keep(Conventional Robust)) ///
	(est3, msymbol(circle) mcolor(black) keep(Conventional Robust)) ///
	(est4, msymbol(triangle) mlcolor(black) mfcolor(white) keep(Conventional Robust)) ///
	(est5, msymbol(square) mlcolor(black) mfcolor(white) keep(Conventional Robust)) ///
	(est6, msymbol(circle) mlcolor(black) mfcolor(white) keep(Conventional Robust)) ///
	(est7, msymbol(triangle) mcolor(gs12) keep(Conventional Robust)) ///
	(est8, msymbol(square) mcolor(gs12) keep(Conventional Robust)) ///
	(est9, msymbol(circle) mcolor(gs12) keep(Conventional Robust)) ///
	(est10, msymbol(triangle) mlcolor(gs12) mfcolor(white) keep(Conventional Robust)) ///
	(est11, msymbol(square) mlcolor(gs12) mfcolor(white) keep(Conventional Robust)) ///
	(est12, msymbol(circle) mlcolor(gs12) mfcolor(white) keep(Conventional Robust)), ///
	vertical scheme(sj) graphregion(color(white)) plotregion(lcolor(black)) ylabel(,format(%9.2f) angle(0)) ytitle("Point estimate") ///
	yline(0) xsize(16) ysize(9) ciopts(recast(rcap) color(black)) legend(label(2 "p = 1, MSE, triangular") label(4 "p = 1, MSE, uniform") ///
	label(6 "p = 1, MSE, epanechnikov") label(8 "p = 1, CER, triangular") ///
	label(10 "p = 1, CER, uniform") label(12 "p = 1, CER, epanechnikov") ///
	label(14 "p = 2, MSE, triangular") label(16 "p = 2, MSE, uniform") ///
	label(18 "p = 2, MSE, epanechnikov") label(20 "p = 2, CER, triangular") ///
	label(22 "p = 2, CER, uniform") label(24 "p = 2, CER, epanechnikov") cols(4)) ///
	subtitle("Panel B: Colombia", position(11))

graph save "$dir/temp/colombia_figureA3.gph", replace

est clear

eststo: rdrobust electednextelection rv if rv!=0 & rv!=. & country=="Denmark", c(0) p(1) all vce(cluster constituency) bwselect(mserd) kernel(triangular) rho(0.85)
eststo: rdrobust electednextelection rv if rv!=0 & rv!=. & country=="Denmark", c(0) p(1) all vce(cluster constituency) bwselect(mserd) kernel(uniform) rho(1)
eststo: rdrobust electednextelection rv if rv!=0 & rv!=. & country=="Denmark", c(0) p(1) all vce(cluster constituency) bwselect(mserd) kernel(epanechnikov) rho(0.898)
eststo: rdrobust electednextelection rv if rv!=0 & rv!=. & country=="Denmark", c(0) p(1) all vce(cluster constituency) bwselect(cerrd) kernel(triangular) rho(0.850)
eststo: rdrobust electednextelection rv if rv!=0 & rv!=. & country=="Denmark", c(0) p(1) all vce(cluster constituency) bwselect(cerrd) kernel(uniform) rho(1)
eststo: rdrobust electednextelection rv if rv!=0 & rv!=. & country=="Denmark", c(0) p(1) all vce(cluster constituency) bwselect(cerrd) kernel(epanechnikov) rho(0.898)
eststo: rdrobust electednextelection rv if rv!=0 & rv!=. & country=="Denmark", c(0) p(2) all vce(cluster constituency) bwselect(mserd) kernel(triangular) rho(0.887)
eststo: rdrobust electednextelection rv if rv!=0 & rv!=. & country=="Denmark", c(0) p(2) all vce(cluster constituency) bwselect(mserd) kernel(uniform) rho(1)
eststo: rdrobust electednextelection rv if rv!=0 & rv!=. & country=="Denmark", c(0) p(2) all vce(cluster constituency) bwselect(mserd) kernel(epanechnikov) rho(0.924)
eststo: rdrobust electednextelection rv if rv!=0 & rv!=. & country=="Denmark", c(0) p(2) all vce(cluster constituency) bwselect(cerrd) kernel(triangular) rho(0.887)
eststo: rdrobust electednextelection rv if rv!=0 & rv!=. & country=="Denmark", c(0) p(2) all vce(cluster constituency) bwselect(cerrd) kernel(uniform) rho(1)
eststo: rdrobust electednextelection rv if rv!=0 & rv!=. & country=="Denmark", c(0) p(2) all vce(cluster constituency) bwselect(cerrd) kernel(epanechnikov) rho(0.924)

coefplot (est1, msymbol(triangle) mcolor(black) keep(Conventional Robust)) ///
	(est2, msymbol(square) mcolor(black) keep(Conventional Robust)) ///
	(est3, msymbol(circle) mcolor(black) keep(Conventional Robust)) ///
	(est4, msymbol(triangle) mlcolor(black) mfcolor(white) keep(Conventional Robust)) ///
	(est5, msymbol(square) mlcolor(black) mfcolor(white) keep(Conventional Robust)) ///
	(est6, msymbol(circle) mlcolor(black) mfcolor(white) keep(Conventional Robust)) ///
	(est7, msymbol(triangle) mcolor(gs12) keep(Conventional Robust)) ///
	(est8, msymbol(square) mcolor(gs12) keep(Conventional Robust)) ///
	(est9, msymbol(circle) mcolor(gs12) keep(Conventional Robust)) ///
	(est10, msymbol(triangle) mlcolor(gs12) mfcolor(white) keep(Conventional Robust)) ///
	(est11, msymbol(square) mlcolor(gs12) mfcolor(white) keep(Conventional Robust)) ///
	(est12, msymbol(circle) mlcolor(gs12) mfcolor(white) keep(Conventional Robust)), ///
	vertical scheme(sj) graphregion(color(white)) plotregion(lcolor(black)) ylabel(,format(%9.2f) angle(0)) ytitle("Point estimate") ///
	xsize(16) ysize(9) ciopts(recast(rcap) color(black)) legend(label(2 "p = 1, MSE, triangular") label(4 "p = 1, MSE, uniform") ///
	label(6 "p = 1, MSE, epanechnikov") label(8 "p = 1, CER, triangular") ///
	label(10 "p = 1, CER, uniform") label(12 "p = 1, CER, epanechnikov") ///
	label(14 "p = 2, MSE, triangular") label(16 "p = 2, MSE, uniform") ///
	label(18 "p = 2, MSE, epanechnikov") label(20 "p = 2, CER, triangular") ///
	label(22 "p = 2, CER, uniform") label(24 "p = 2, CER, epanechnikov") cols(4)) ///
	subtitle("Panel C: Denmark", position(11))

graph save "$dir/temp/denmark_figureA3.gph", replace

est clear

eststo: rdrobust electednextelection rv if rv!=0 & rv!=. & country=="Finland", c(0) p(1) all vce(cluster constituency) bwselect(mserd) kernel(triangular) rho(0.85)
eststo: rdrobust electednextelection rv if rv!=0 & rv!=. & country=="Finland", c(0) p(1) all vce(cluster constituency) bwselect(mserd) kernel(uniform) rho(1)
eststo: rdrobust electednextelection rv if rv!=0 & rv!=. & country=="Finland", c(0) p(1) all vce(cluster constituency) bwselect(mserd) kernel(epanechnikov) rho(0.898)
eststo: rdrobust electednextelection rv if rv!=0 & rv!=. & country=="Finland", c(0) p(1) all vce(cluster constituency) bwselect(cerrd) kernel(triangular) rho(0.850)
eststo: rdrobust electednextelection rv if rv!=0 & rv!=. & country=="Finland", c(0) p(1) all vce(cluster constituency) bwselect(cerrd) kernel(uniform) rho(1)
eststo: rdrobust electednextelection rv if rv!=0 & rv!=. & country=="Finland", c(0) p(1) all vce(cluster constituency) bwselect(cerrd) kernel(epanechnikov) rho(0.898)
eststo: rdrobust electednextelection rv if rv!=0 & rv!=. & country=="Finland", c(0) p(2) all vce(cluster constituency) bwselect(mserd) kernel(triangular) rho(0.887)
eststo: rdrobust electednextelection rv if rv!=0 & rv!=. & country=="Finland", c(0) p(2) all vce(cluster constituency) bwselect(mserd) kernel(uniform) rho(1)
eststo: rdrobust electednextelection rv if rv!=0 & rv!=. & country=="Finland", c(0) p(2) all vce(cluster constituency) bwselect(mserd) kernel(epanechnikov) rho(0.924)
eststo: rdrobust electednextelection rv if rv!=0 & rv!=. & country=="Finland", c(0) p(2) all vce(cluster constituency) bwselect(cerrd) kernel(triangular) rho(0.887)
eststo: rdrobust electednextelection rv if rv!=0 & rv!=. & country=="Finland", c(0) p(2) all vce(cluster constituency) bwselect(cerrd) kernel(uniform) rho(1)
eststo: rdrobust electednextelection rv if rv!=0 & rv!=. & country=="Finland", c(0) p(2) all vce(cluster constituency) bwselect(cerrd) kernel(epanechnikov) rho(0.924)

coefplot (est1, msymbol(triangle) mcolor(black) keep(Conventional Robust)) ///
	(est2, msymbol(square) mcolor(black) keep(Conventional Robust)) ///
	(est3, msymbol(circle) mcolor(black) keep(Conventional Robust)) ///
	(est4, msymbol(triangle) mlcolor(black) mfcolor(white) keep(Conventional Robust)) ///
	(est5, msymbol(square) mlcolor(black) mfcolor(white) keep(Conventional Robust)) ///
	(est6, msymbol(circle) mlcolor(black) mfcolor(white) keep(Conventional Robust)) ///
	(est7, msymbol(triangle) mcolor(gs12) keep(Conventional Robust)) ///
	(est8, msymbol(square) mcolor(gs12) keep(Conventional Robust)) ///
	(est9, msymbol(circle) mcolor(gs12) keep(Conventional Robust)) ///
	(est10, msymbol(triangle) mlcolor(gs12) mfcolor(white) keep(Conventional Robust)) ///
	(est11, msymbol(square) mlcolor(gs12) mfcolor(white) keep(Conventional Robust)) ///
	(est12, msymbol(circle) mlcolor(gs12) mfcolor(white) keep(Conventional Robust)), ///
	vertical scheme(sj) graphregion(color(white)) plotregion(lcolor(black)) ylabel(,format(%9.2f) angle(0)) ytitle("Point estimate") ///
	yline(0) xsize(16) ysize(9) ciopts(recast(rcap) color(black)) legend(label(2 "p = 1, MSE, triangular") label(4 "p = 1, MSE, uniform") ///
	label(6 "p = 1, MSE, epanechnikov") label(8 "p = 1, CER, triangular") ///
	label(10 "p = 1, CER, uniform") label(12 "p = 1, CER, epanechnikov") ///
	label(14 "p = 2, MSE, triangular") label(16 "p = 2, MSE, uniform") ///
	label(18 "p = 2, MSE, epanechnikov") label(20 "p = 2, CER, triangular") ///
	label(22 "p = 2, CER, uniform") label(24 "p = 2, CER, epanechnikov") cols(4)) ///
	subtitle("Panel D: Finland", position(11))

graph save "$dir/temp/finland_figureA3.gph", replace

grc1leg "$dir/temp/brazil_figureA3.gph" "$dir/temp/colombia_figureA3.gph" ///
	"$dir/temp/denmark_figureA3.gph" "$dir/temp/finland_figureA3.gph", ///
	legendfrom("$dir/temp/finland_figureA3.gph") ///
	graphregion(color(white)) cols(2)
graph display, xsize(20) ysize(10)
graph export "$dir/figures/Figure_OA4.pdf", as(pdf) replace
